<template>
    <div class="container-common manage-score-composition">
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item>成绩管理</el-breadcrumb-item>
            <el-breadcrumb-item>成绩组成设置</el-breadcrumb-item>
        </el-breadcrumb>
        <!--<el-button class="add-score" type="primary">+ 添加外部成绩</el-button>-->
        <el-table
                :data="tableData"
                border
                style="width: 100%">
            <el-table-column
                    prop="name"
                    label="名称">
            </el-table-column>
            <el-table-column
                    prop="percent"
                    label="占比">
                <template slot-scope="scope">
                    <el-input
                            size="small"
                            v-model="scope.row.percent">
                    </el-input>
                </template>
            </el-table-column>
            <!--<el-table-column-->
                    <!--label="操作"-->
                    <!--width="160">-->
                <!--<template slot-scope="scope">-->
                    <!--<el-button-->
                            <!--type="text"-->
                            <!--size="large"-->
                            <!--:disabled="!scope.row.canDelete"-->
                            <!--@click="handleDelete(scope.row)">删除</el-button>-->
                <!--</template>-->
            <!--</el-table-column>-->
        </el-table>
        <el-button class="confirm-score-composition" type="primary" @click="savePercent">保存</el-button>
        <!--<el-dialog-->
                <!--title="提示"-->
                <!--:visible.sync="deleteDialogVisible"-->
                <!--width="30%">-->
            <!--<span v-if="currentData">确认删除{{currentData.id}}吗？</span>-->
            <!--<span slot="footer" class="dialog-footer">-->
                <!--<el-button @click="cancelDelete">取 消</el-button>-->
                <!--<el-button type="primary" @click="confirmDelete">确 定</el-button>-->
            <!--</span>-->
        <!--</el-dialog>-->
    </div>
</template>

<script>
    import Api from '@utils/api';
    import { mapGetters } from 'vuex';

    export default {
        name: "composition",
        data () {
            return {
                tableData: [],
                // deleteDialogVisible: false,
                currentData: null,
                // addDialogVisible: false,
                // addForm: {
                //     name: ''
                // }
            }
        },
        computed: {
            ...mapGetters([
                'getCurrentCourseId'
            ])
        },
        methods: {
            // handleModify (data) {},
            // handleDelete (data) {
            //     this.currentData = data;
            //     this.deleteDialogVisible = true;
            // },
            // cancelDelete () {
            //     this.deleteDialogVisible = false;
            // },
            // confirmDelete () {
            //     Api({
            //         method: 'post',
            //         url: '/manageStudentOutlineDelete',
            //         data: {
            //             course_id: this.getCurrentCourseId,
            //             student: this.currentData.id
            //         }
            //     }).then(() => {
            //         this.$notify({
            //             type: 'success',
            //             title: '删除成功！'
            //         });
            //
            //         this.cancelDelete();
            //         this.getTableData();
            //     })
            // },
            savePercent () {
                let param = {};

                this.tableData.forEach(item => {
                    param[item.id] = item.percent
                });

                Api({
                    method: 'post',
                    url: '/setScoreRate',
                    data: param
                }).then(() => {
                    this.$notify({
                        title: '保存成功！',
                        type: 'success'
                    });
                });
            },
            getTableData () {
                Api({
                    method: 'post',
                    url: '/getScoreRate',
                    data: {
                        course_id: this.getCurrentCourseId
                    }
                }).then(res => {
                    if (res.data && res.data.data && res.data.data.length) {
                        this.tableData = res.data.data.map(item => {
                            return {
                                id: item.task_id,
                                name: item.task_name,
                                percent: item.task_percentage,
                                canDelete: item.can_delete
                            }
                        });
                    }
                })
            }
        },
        created () {
            this.getTableData();
        }
    }
</script>

<style type="text/scss" lang="scss">
    .manage-score-composition {
        .add-score {
            margin-bottom: 20px;
        }
        .confirm-score-composition {
            margin: 20px 0;
        }
    }
</style>